package com.maolong.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.maolong.mapper.MenuMapper;
import com.maolong.mapper.RoleRightMapper;
import com.maolong.pojo.dto.RoleRightDTO;
import com.maolong.pojo.entity.RoleMenu;
import com.maolong.service.MenuService;
import com.maolong.service.RoleRightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RoleRightServiceImpl implements RoleRightService {
    @Autowired
    RoleRightMapper roleRightMapper;

    @Autowired
    MenuService menuService;
    @Autowired
    MenuMapper menuMapper;

    /**
     * 实现对于菜单操作的保存
     */
    @Override
    @Transactional
    public void save(RoleRightDTO roleRightDTO) {
        //先把所有有关role_id的都删除了
        roleRightMapper.deleteByRoleId(roleRightDTO.getRoleId());
        //然后保存新的
        roleRightMapper.addBatch(roleRightDTO);
    }

    @Override
    public List<RoleMenu> selectRoleRight(Integer id) {
        return roleRightMapper.selectList(new QueryWrapper<RoleMenu>().eq("role_id",id));
    }

}
